import request from '@/utils/http.js'

/* 
	注册
	data = {
		name,
		username,
		password,
	}
*/

export const register = (data) => {
	return request({
		method: 'POST',
		url: '/register',
		data
	})
}

/* 
	登录
	data = {
		username,
		password,
	}
*/

export const login = (data) => {
	return request({
		method: 'POST',
		url: '/login',
		data
	})
}

/* 
	获取用户信息
*/

export const getUserInfo = (id) => {
	return request({
		method: 'GET',
		url: `/user/${id}`
	})
}

/* 
	上传用户头像
*/

export const uploadAvatar = (data) => {
	return request({
		method: 'POST',
		url: '/upload',
		data
	})
}

/* 
	更新用户信息
*/

export const updateUserInfo = (id,data) => {
	return request({
		method: 'POST',
		url: `/update/${id}`,
		data
	})
}

/* 
	获取分类信息
*/

export const getCategory = () => {
	return request({
		method: 'GET',
		url: '/category'
	})
}

/* 
	获取分类下的文章信息
	params = {
		page
		pagesize
	}
*/

export const getArticle = (id,params) => {
	return request({
		method: 'GET',
		url: `/detail/${id}`,
		params
	})
}

/* 
	获取文章详情信息
*/

export const getArticleDetail = (id) => {
	return request({
		method: 'GET',
		url: `/article/${id}`
	})
}


/* 
	获取推荐文章
*/

export const getCommend = () => {
	return request({
		method: 'GET',
		url: '/commend'		
	})
}

/* 
	获取文章评论
*/

export const getComment = (id) => {
	return request({
		method: 'GET',
		url: `/comment/${id}`		
	})
}

/* 
	评论文章
	data = {
		comment_content: ,
		comment_date: ,
		parent_id: ,
		article_id:
	}
*/

export const postComment = (id,data) => {
	return request({
		method: 'POST',
		url: `/comment_post/${id}`,
		data
	})
}

/* 
	获取文章是否收藏
	路径参数为用户id
	params = {
		article_id   文章id
	}
*/

export const getCollection = (id,params) => {
	return request({
		method: 'GET',
		url: `/collection/${id}`,
		params
	})
}

/* 
	更新收藏文章
	路径参数为用户id
	data = {
		article_id   文章id
	}
*/

export const updateCollection = (id,data) => {
	return request({
		method: 'POST',
		url: `/collection/${id}`,
		data
	})
}

/* 
	获取作者是否关注
	路径参数为用户id
	params = {
		sub_id   文章发布者 id
	}
*/

export const getFollow = (id,params) => {
	return request({
		method: 'GET',
		url: `/sub_scription/${id}`,
		params
	})
}

/* 
	更新关注作者
	路径参数为用户 id
	data = {
		sub_id   文章发布者 id
	}
*/

export const updateFollow = (id,data) => {
	return request({
		method: 'POST',
		url: `/sub_scription/${id}`,
		data
	})
}